using System;
using System.Linq;
using System.Data.Objects;
using System.Data.Objects.DataClasses;
using System.ComponentModel;
using System.Runtime.Serialization;
using System.Collections.Generic;
using Acme.AuditExample.EFDAL.Entity;

[assembly: EdmSchemaAttribute()]
#region EDM Relationship Metadata


#endregion

namespace Acme.AuditExample.EFDAL
{
	#region TableMappingConstants Enumeration

	/// <summary>
	/// A map for all entity types in this library
	/// </summary>
	public enum TableMappingConstants
	{
		/// <summary>
		/// A mapping for the the Customer entity
		/// </summary>
		Customer,
	}

	#endregion

	#region AuditTypeConstants Enumeration

	/// <summary>
	/// A set of values for the types of audits
	/// </summary>
	public enum AuditTypeConstants
	{
		/// <summary>
		/// Represents a row insert
		/// </summary>
		Insert = 1,
		/// <summary>
		/// Represents a row update
		/// </summary>
		Update = 2,
		/// <summary>
		/// Represents a row delete
		/// </summary>
		Delete = 3,
	}

	#endregion

	#region Entity Context

	/// <summary>
	/// There are no comments for AuditExampleEntities in the schema.
	/// </summary>
	public partial class AuditExampleEntities : System.Data.Objects.ObjectContext
	{
		/// <summary>
		/// The audit modifier used to mark database edits
		/// </summary>
		protected ContextStartup _contextStartup = new ContextStartup(null);

		/// <summary>
		/// Initializes a new AuditExampleEntities object using the connection string found in the 'AuditExampleEntities' section of the application configuration file.
		/// </summary>
		public AuditExampleEntities() :
			base("name=AuditExampleEntities", "AuditExampleEntities")
		{
			this.OnContextCreated();
		}

		/// <summary>
		/// Initialize a new AuditExampleEntities object with an audit modifier.
		/// </summary>
		public AuditExampleEntities(ContextStartup contextStartup) :
			base("name=AuditExampleEntities", "AuditExampleEntities")
		{
			_contextStartup = contextStartup;
			this.OnContextCreated();
		}

		/// <summary>
		/// Initialize a new AuditExampleEntities object.
		/// </summary>
		public AuditExampleEntities(string connectionString) :
			base(connectionString, "AuditExampleEntities")
		{
			this.OnContextCreated();
		}

		/// <summary>
		/// Initialize a new AuditExampleEntities object.
		/// </summary>
		public AuditExampleEntities(System.Data.EntityClient.EntityConnection connection) :
			base(connection, "AuditExampleEntities")
		{
			this.OnContextCreated();
		}

		partial void OnContextCreated();

		/// <summary>
		/// There are no comments for Customer in the schema.
		/// </summary>
		public virtual System.Data.Objects.ObjectSet<Acme.AuditExample.EFDAL.Entity.Customer> Customer
		{
			get
			{
				if ((this._customer == null))
				{
					this._customer = base.CreateObjectSet<Acme.AuditExample.EFDAL.Entity.Customer>("Customer");
				}
				return this._customer;
			}
		}

		/// <summary>
		/// The internal reference variable for the 'Customer' object set
		/// </summary>
		protected System.Data.Objects.ObjectSet<Acme.AuditExample.EFDAL.Entity.Customer> _customer;

		#region AddItem Methods

		/// <summary>
		/// Adds an object of type 'Customer' to the object context.
		/// </summary>
		/// <param name="entity">The entity to add</param>
		public virtual void AddItem(Acme.AuditExample.EFDAL.Entity.Customer entity)
		{
			entity.CreatedBy = _contextStartup.Modifer;
			entity.ModifiedBy = _contextStartup.Modifer;
			base.AddObject("Customer", entity);
		}

		/// <summary>
		/// Adds an object to the object context.
		/// </summary>
		[Obsolete("This method signature is no longer used. Use the AddItem method.", true)]
		[System.ComponentModel.EditorBrowsable(EditorBrowsableState.Never)]
		public new void AddObject(string entitySetName, object entity)
		{
			throw new Exception("This method signature is no longer used. Use the AddItem method.");
		}

		#endregion

		internal static string GetConnectionString()
		{
			string s = System.Configuration.ConfigurationManager.ConnectionStrings["AuditExampleEntities"].ConnectionString;
			System.Text.RegularExpressions.Regex regEx = new System.Text.RegularExpressions.Regex("provider connection string\\s*=\\s*\"([^\"]*)");
			System.Text.RegularExpressions.Match m = regEx.Match(s);
			string connString = string.Empty;
			if (m != null && m.Groups.Count > 1)
			{
				connString = m.Groups[1].Value;
			}
			return connString;
		}

		private string GetConnString()
		{
			string s = this.Connection.ConnectionString;
			System.Text.RegularExpressions.Regex regEx = new System.Text.RegularExpressions.Regex("provider connection string\\s*=\\s*\"([^\"]*)");
			System.Text.RegularExpressions.Match m = regEx.Match(s);
			string connString = string.Empty;
			if (m != null && m.Groups.Count > 1)
			{
				connString = m.Groups[1].Value;
			}
			return connString;
		}

	}

	#endregion

}
